<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "pay-order",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { reactive } from "vue";
import UserSelect from "/$/user/components/user-select.vue";

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	orderType: [
		{ label: t("充值余额"), value: 0 },
		{ label: t("购买流量"), value: 1 },
		{ label: t("电话通知充值"), value: 2 },
		{ label: t("物联网卡充值"), value: 3 },
		{ label: t("短信通知充值"), value: 4 },
	],
	status: [
		{ label: t("待支付"), value: 0 },
		{ label: t("已支付"), value: 1 },
		{ label: t("已取消"), value: 2 },
		{ label: t("已退款"), value: 3 },
	],
	paymentMethod: [
		{ label: t("微信支付"), value: 0 },
		{ label: t("支付宝"), value: 1 },
		{ label: t("余额支付"), value: 2 },
		{ label: t("银行卡"), value: 3 },
	],
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("选择用户"),
			prop: "userId",
			component: { vm: UserSelect },
			required: true,
		},
		{
			label: t("订单号"),
			prop: "orderNo",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		{
			label: t("订单标题"),
			prop: "title",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("订单描述"),
			prop: "description",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("订单类型"),
			prop: "orderType",
			component: {
				name: "cl-select",
				props: { options: options.orderType },
			},
			value: 0,
			span: 12,
			required: true,
		},
		{
			label: t("订单金额"),
			prop: "amount",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		{
			label: t("订单状态"),
			prop: "status",
			component: { name: "el-radio-group", options: options.status },
			value: 0,
			required: true,
		},
		{
			label: t("支付方式"),
			prop: "paymentMethod",
			component: {
				name: "el-radio-group",
				options: options.paymentMethod,
			},
			value: 0,
			required: true,
		},
		{
			label: t("支付时间"),
			prop: "payTime",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
			},
			span: 12,
		},
		{
			label: t("取消时间"),
			prop: "cancelTime",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
			},
			span: 12,
		},
		{
			label: t("退款时间"),
			prop: "refundTime",
			component: {
				name: "el-date-picker",
				props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
			},
			span: 12,
		},
		{
			label: t("选择业务"),
			prop: "businessId",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("业务类型"),
			prop: "businessType",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("扩展信息"),
			prop: "extInfo",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("备注"),
			prop: "remark",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("充值金额"),
			prop: "rechargeAmount",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("流量包大小(MB)"),
			prop: "trafficSize",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("流量包有效期(天)"),
			prop: "trafficValidDays",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("充值分钟数"),
			prop: "callMinutes",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("物联网卡ICCID"),
			prop: "iccid",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("物联网卡充值流量(MB)"),
			prop: "iotTrafficSize",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("短信条数"),
			prop: "smsCount",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
	],
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: t("手机号"), prop: "userPhone", minWidth: 120 },
		{ label: t("昵称"), prop: "userNickName", minWidth: 120 },
		{ label: t("订单号"), prop: "orderNo", minWidth: 120 },
		{ label: t("订单标题"), prop: "title", minWidth: 120 },
		{ label: t("订单描述"), prop: "description", minWidth: 120 },
		{
			label: t("订单类型"),
			prop: "orderType",
			minWidth: 120,
			dict: options.orderType,
		},
		{ label: t("订单金额"), prop: "amount", minWidth: 120 },
		{
			label: t("订单状态"),
			prop: "status",
			minWidth: 120,
			dict: options.status,
		},
		{
			label: t("支付方式"),
			prop: "paymentMethod",
			minWidth: 120,
			dict: options.paymentMethod,
		},
		{
			label: t("支付时间"),
			prop: "payTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{
			label: t("取消时间"),
			prop: "cancelTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{
			label: t("退款时间"),
			prop: "refundTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{ label: t("业务ID"), prop: "businessId", minWidth: 120 },
		{ label: t("业务类型"), prop: "businessType", minWidth: 120 },
		{ label: t("扩展信息"), prop: "extInfo", minWidth: 120 },
		{ label: t("备注"), prop: "remark", minWidth: 120 },
		{ label: t("充值金额"), prop: "rechargeAmount", minWidth: 120 },
		{ label: t("流量包大小(MB)"), prop: "trafficSize", minWidth: 120 },
		{
			label: t("流量包有效期(天)"),
			prop: "trafficValidDays",
			minWidth: 120,
		},
		{ label: t("充值分钟数"), prop: "callMinutes", minWidth: 120 },
		{ label: t("物联网卡ICCID"), prop: "iccid", minWidth: 120 },
		{
			label: t("物联网卡充值流量(MB)"),
			prop: "iotTrafficSize",
			minWidth: 120,
		},
		{ label: t("短信条数"), prop: "smsCount", minWidth: 120 },
		{
			label: t("创建时间"),
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" },
		},
		{
			label: t("更新时间"),
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{ type: "op", buttons: ["edit", "delete"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.pay.order,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
